home *** CD-ROM | disk | FTP | other *** search
- Path: news1.cris.com!news
- From: aubrey@concentric.net (Aubrey Harrison)
- Newsgroups: comp.lang.c
- Subject: Re: C beginner needs your help ASAP
- Date: 18 Feb 1996 22:51:25 GMT
- Organization: Concentric Internet Services
- Distribution: world
- Message-ID: <4g8ahd$p8b@spectator.cris.com>
- References: <4g862f$p0b@risky.ecs.umass.edu>
- NNTP-Posting-Host: cnc022033.concentric.net
- Mime-Version: 1.0
- Content-Type: Text/Plain; charset=US-ASCII
- X-Newsreader: WinVN 0.99.6
-
- In article <4g862f$p0b@risky.ecs.umass.edu>, sebag@ecs.umass.edu says...
- >
- >I am a new C programmmer who desperately needs help.
- >I have been digging in the manuals for a way to do this but have still
- >come out empty handed. Here is the problem: I want to open files in a while
- >loop with different filenames. data0,data1,data2,data3, .. data1000 , ...
- >I need to increment an integer each time around then convert it to a string
- >and then somehow use strcat to combine the "data" with the integer string.
- >After that use fopen(filename, "a");
- >
- >If you know how to do this, please email me. It would take you 2 minutes but
- >it is taking me two days so far. Code would be extremly useful.
- >Thanks, sebag@ecs.umass.edu
-
- This is how I would do it. I tested it and it seems to do what you want. Of
- course, I am no expert, in fact I was called "ignorant and idiot" by Mister Dan
- Pop, the self-appointed comp.lang.c.police, for helping someone earlier, so I
- guess I am not worthy of posting here, but somehow I feel a little better after
- helping someone, instead of attacking and belittling them because I somehow see
- myself as superior when I don't really know anything about them.
-
- #include <stdio.h>
-
- main()
- {
- char buf[3],filename[9];
- int i;
-
- for(i=0; i<10; i++)
- {
- sprintf(buf,"%d",i);
- strcpy( filename,"data");
- strcat( filename, buf );
- strcat( filename, ".ext");
- printf( "%s\n", filename);
- }
-
- }
-
- --
- =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- Aubrey Harrison aubrey@concentric.net 75320.1606@compuserve.com
- =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- Loneliness is to endure the presence of one who does not understand.
- -Elbert Hubbard (1856-1915)
- =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-
-